package o;

import com.google.android.exoplayer2.ParserException;
import java.util.Arrays;

final class afv {

    public static final class a {
        public final int ˊ;
        public final int ˋ;
        public final boolean ˎ;
        public final int ॱ;

        public a(boolean z, int i, int i2, int i3) {
            this.ˎ = z;
            this.ˋ = i;
            this.ॱ = i2;
            this.ˊ = i3;
        }
    }

    public static final class b {
        public final long[] ˊ;
        public final int ˋ;
        public final boolean ˎ;
        public final int ˏ;
        public final int ॱ;

        public b(int i, int i2, long[] jArr, int i3, boolean z) {
            this.ॱ = i;
            this.ˏ = i2;
            this.ˊ = jArr;
            this.ˋ = i3;
            this.ˎ = z;
        }
    }

    public static final class c {
        public final String ˋ;
        public final int ˎ;
        public final String[] ˏ;

        public c(String str, String[] strArr, int i) {
            this.ˋ = str;
            this.ˏ = strArr;
            this.ˎ = i;
        }
    }

    public static final class e {
        public final int ʻ;
        public final int ʼ;
        public final byte[] ʽ;
        public final int ˊ;
        public final long ˋ;
        public final int ˎ;
        public final int ˏ;
        public final long ॱ;
        public final int ॱॱ;
        public final boolean ᐝ;

        public e(long j, int i, long j2, int i2, int i3, int i4, int i5, int i6, boolean z, byte[] bArr) {
            this.ॱ = j;
            this.ˊ = i;
            this.ˋ = j2;
            this.ˏ = i2;
            this.ˎ = i3;
            this.ʻ = i4;
            this.ʼ = i5;
            this.ॱॱ = i6;
            this.ᐝ = z;
            this.ʽ = bArr;
        }
    }

    public static int ˋ(int i) {
        int i2 = 0;
        while (i > 0) {
            i2++;
            i >>>= 1;
        }
        return i2;
    }

    public static e ˊ(anc o_anc) throws ParserException {
        ˋ(1, o_anc, false);
        long ॱˊ = o_anc.ॱˊ();
        int ʽ = o_anc.ʽ();
        long ॱˊ2 = o_anc.ॱˊ();
        int ᐝॱ = o_anc.ᐝॱ();
        int ᐝॱ2 = o_anc.ᐝॱ();
        int ᐝॱ3 = o_anc.ᐝॱ();
        int ʽ2 = o_anc.ʽ();
        return new e(ॱˊ, ʽ, ॱˊ2, ᐝॱ, ᐝॱ2, ᐝॱ3, (int) Math.pow(2.0d, (double) (ʽ2 & 15)), (int) Math.pow(2.0d, (double) ((ʽ2 & 240) >> 4)), (o_anc.ʽ() & 1) > 0, Arrays.copyOf(o_anc.ˏ, o_anc.ॱ()));
    }

    public static c ॱ(anc o_anc) throws ParserException {
        int i = 0;
        ˋ(3, o_anc, false);
        String ˊ = o_anc.ˊ((int) o_anc.ॱˊ());
        int length = ˊ.length() + 11;
        long ॱˊ = o_anc.ॱˊ();
        String[] strArr = new String[((int) ॱˊ)];
        length += 4;
        while (((long) i) < ॱˊ) {
            length += 4;
            strArr[i] = o_anc.ˊ((int) o_anc.ॱˊ());
            length += strArr[i].length();
            i++;
        }
        if ((o_anc.ʽ() & 1) != 0) {
            return new c(ˊ, strArr, length + 1);
        }
        throw new ParserException("framing bit expected to be set");
    }

    public static boolean ˋ(int i, anc o_anc, boolean z) throws ParserException {
        if (o_anc.ˊ() < 7) {
            if (z) {
                return false;
            }
            throw new ParserException("too short header: " + o_anc.ˊ());
        } else if (o_anc.ʽ() != i) {
            if (z) {
                return false;
            }
            throw new ParserException("expected header type " + Integer.toHexString(i));
        } else if (o_anc.ʽ() == 118 && o_anc.ʽ() == 111 && o_anc.ʽ() == 114 && o_anc.ʽ() == 98 && o_anc.ʽ() == 105 && o_anc.ʽ() == 115) {
            return true;
        } else {
            if (z) {
                return false;
            }
            throw new ParserException("expected characters 'vorbis'");
        }
    }

    public static a[] ˊ(anc o_anc, int i) throws ParserException {
        int i2;
        int i3 = 0;
        ˋ(5, o_anc, false);
        int ʽ = o_anc.ʽ() + 1;
        afu o_afu = new afu(o_anc.ˏ);
        o_afu.ˎ(o_anc.ˋ() * 8);
        for (i2 = 0; i2 < ʽ; i2++) {
            ॱ(o_afu);
        }
        i2 = o_afu.ॱ(6) + 1;
        while (i3 < i2) {
            if (o_afu.ॱ(16) != 0) {
                throw new ParserException("placeholder of time domain transforms not zeroed out");
            }
            i3++;
        }
        ˋ(o_afu);
        ˎ(o_afu);
        ˎ(i, o_afu);
        a[] ˏ = ˏ(o_afu);
        if (o_afu.ˏ()) {
            return ˏ;
        }
        throw new ParserException("framing bit after modes not set as expected");
    }

    private static a[] ˏ(afu o_afu) {
        int ॱ = o_afu.ॱ(6) + 1;
        a[] aVarArr = new a[ॱ];
        for (int i = 0; i < ॱ; i++) {
            aVarArr[i] = new a(o_afu.ˏ(), o_afu.ॱ(16), o_afu.ॱ(16), o_afu.ॱ(8));
        }
        return aVarArr;
    }

    private static void ˎ(int i, afu o_afu) throws ParserException {
        int ॱ = o_afu.ॱ(6) + 1;
        for (int i2 = 0; i2 < ॱ; i2++) {
            int ॱ2 = o_afu.ॱ(16);
            switch (ॱ2) {
                case 0:
                    int i3;
                    if (o_afu.ˏ()) {
                        ॱ2 = o_afu.ॱ(4) + 1;
                    } else {
                        ॱ2 = 1;
                    }
                    if (o_afu.ˏ()) {
                        int ॱ3 = o_afu.ॱ(8) + 1;
                        for (i3 = 0; i3 < ॱ3; i3++) {
                            o_afu.ˎ(ˋ(i - 1));
                            o_afu.ˎ(ˋ(i - 1));
                        }
                    }
                    if (o_afu.ॱ(2) == 0) {
                        if (ॱ2 > 1) {
                            for (i3 = 0; i3 < i; i3++) {
                                o_afu.ˎ(4);
                            }
                        }
                        for (i3 = 0; i3 < ॱ2; i3++) {
                            o_afu.ˎ(8);
                            o_afu.ˎ(8);
                            o_afu.ˎ(8);
                        }
                        break;
                    }
                    throw new ParserException("to reserved bits must be zero after mapping coupling steps");
                default:
                    amz.ˋ("VorbisUtil", "mapping type other than 0 not supported: " + ॱ2);
                    break;
            }
        }
    }

    private static void ˎ(afu o_afu) throws ParserException {
        int ॱ = o_afu.ॱ(6) + 1;
        for (int i = 0; i < ॱ; i++) {
            if (o_afu.ॱ(16) > 2) {
                throw new ParserException("residueType greater than 2 is not decodable");
            }
            int i2;
            o_afu.ˎ(24);
            o_afu.ˎ(24);
            o_afu.ˎ(24);
            int ॱ2 = o_afu.ॱ(6) + 1;
            o_afu.ˎ(8);
            int[] iArr = new int[ॱ2];
            for (i2 = 0; i2 < ॱ2; i2++) {
                int ॱ3;
                int ॱ4 = o_afu.ॱ(3);
                if (o_afu.ˏ()) {
                    ॱ3 = o_afu.ॱ(5);
                } else {
                    ॱ3 = 0;
                }
                iArr[i2] = (ॱ3 * 8) + ॱ4;
            }
            for (i2 = 0; i2 < ॱ2; i2++) {
                for (ॱ3 = 0; ॱ3 < 8; ॱ3++) {
                    if ((iArr[i2] & (1 << ॱ3)) != 0) {
                        o_afu.ˎ(8);
                    }
                }
            }
        }
    }

    private static void ˋ(afu o_afu) throws ParserException {
        int ॱ = o_afu.ॱ(6) + 1;
        for (int i = 0; i < ॱ; i++) {
            int ॱ2 = o_afu.ॱ(16);
            int ॱ3;
            switch (ॱ2) {
                case 0:
                    o_afu.ˎ(8);
                    o_afu.ˎ(16);
                    o_afu.ˎ(16);
                    o_afu.ˎ(6);
                    o_afu.ˎ(8);
                    ॱ3 = o_afu.ॱ(4) + 1;
                    for (ॱ2 = 0; ॱ2 < ॱ3; ॱ2++) {
                        o_afu.ˎ(8);
                    }
                    break;
                case 1:
                    int ॱ4;
                    int ॱ5 = o_afu.ॱ(5);
                    ॱ2 = -1;
                    int[] iArr = new int[ॱ5];
                    for (ॱ3 = 0; ॱ3 < ॱ5; ॱ3++) {
                        iArr[ॱ3] = o_afu.ॱ(4);
                        if (iArr[ॱ3] > ॱ2) {
                            ॱ2 = iArr[ॱ3];
                        }
                    }
                    int[] iArr2 = new int[(ॱ2 + 1)];
                    for (ॱ2 = 0; ॱ2 < iArr2.length; ॱ2++) {
                        iArr2[ॱ2] = o_afu.ॱ(3) + 1;
                        ॱ4 = o_afu.ॱ(2);
                        if (ॱ4 > 0) {
                            o_afu.ˎ(8);
                        }
                        for (ॱ3 = 0; ॱ3 < (1 << ॱ4); ॱ3++) {
                            o_afu.ˎ(8);
                        }
                    }
                    o_afu.ˎ(2);
                    int ॱ6 = o_afu.ॱ(4);
                    ॱ2 = 0;
                    ॱ4 = 0;
                    for (ॱ3 = 0; ॱ3 < ॱ5; ॱ3++) {
                        ॱ4 += iArr2[iArr[ॱ3]];
                        while (ॱ2 < ॱ4) {
                            o_afu.ˎ(ॱ6);
                            ॱ2++;
                        }
                    }
                    break;
                default:
                    throw new ParserException("floor type greater than 1 not decodable: " + ॱ2);
            }
        }
    }

    private static b ॱ(afu o_afu) throws ParserException {
        int i = 0;
        if (o_afu.ॱ(24) != 5653314) {
            throw new ParserException("expected code book to start with [0x56, 0x43, 0x42] at " + o_afu.ॱ());
        }
        int i2;
        int ॱ = o_afu.ॱ(16);
        int ॱ2 = o_afu.ॱ(24);
        long[] jArr = new long[ॱ2];
        boolean ˏ = o_afu.ˏ();
        if (ˏ) {
            int ॱ3 = o_afu.ॱ(5) + 1;
            i2 = 0;
            while (i2 < jArr.length) {
                int ॱ4 = o_afu.ॱ(ˋ(ॱ2 - i2));
                int i3 = 0;
                while (i3 < ॱ4 && i2 < jArr.length) {
                    jArr[i2] = (long) ॱ3;
                    i3++;
                    i2++;
                }
                ॱ3++;
            }
        } else {
            boolean ˏ2 = o_afu.ˏ();
            while (i < jArr.length) {
                if (!ˏ2) {
                    jArr[i] = (long) (o_afu.ॱ(5) + 1);
                } else if (o_afu.ˏ()) {
                    jArr[i] = (long) (o_afu.ॱ(5) + 1);
                } else {
                    jArr[i] = 0;
                }
                i++;
            }
        }
        i2 = o_afu.ॱ(4);
        if (i2 > 2) {
            throw new ParserException("lookup type greater than 2 not decodable: " + i2);
        }
        if (i2 == 1 || i2 == 2) {
            long j;
            o_afu.ˎ(32);
            o_afu.ˎ(32);
            i = o_afu.ॱ(4) + 1;
            o_afu.ˎ(1);
            if (i2 != 1) {
                j = ((long) ॱ2) * ((long) ॱ);
            } else if (ॱ != 0) {
                j = ˏ((long) ॱ2, (long) ॱ);
            } else {
                j = 0;
            }
            o_afu.ˎ((int) (j * ((long) i)));
        }
        return new b(ॱ, ॱ2, jArr, i2, ˏ);
    }

    private static long ˏ(long j, long j2) {
        return (long) Math.floor(Math.pow((double) j, 1.0d / ((double) j2)));
    }
}
